﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HongYeSystemWebApi.Templet.Entity.Request
{
    public class SortRequest  
    {
        /// <summary>
        /// 排序字段
        /// </summary>
        public List<SortField> SortFields { get; set; }

        /// <summary>
        /// 获取排序规则
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, bool> GetOrderByProperties()
        {
            Dictionary<string, bool> orderByPropertyDic = null;
            if (SortFields != null && SortFields.Any())
            {
                orderByPropertyDic = new Dictionary<string, bool>();
                SortFields.ForEach(sortField =>
                {
                    orderByPropertyDic.Add(sortField.SortFiled, sortField.IsAsc.Value);
                });
            }
            else
            {
                orderByPropertyDic = new Dictionary<string, bool>
                {
                    { "id",false}
                };
            }
            return orderByPropertyDic;
        }
    }
    public class SortField
    {
        /// <summary>
        /// 排序字段
        /// </summary>
        public string SortFiled { get; set; }

        /// <summary>
        /// 是否升序（默认升序）
        /// </summary>
        public bool? IsAsc { get; set; } = true;
    }
}
